package com.atguigu.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.atguigu.common.utils.Constant;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.member.feign.OrderFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@Slf4j
public class MemberWebController {

    @Autowired
    private OrderFeignService orderFeignService;

    @RequestMapping("/web/member/order")
    public String memberOrderList(@RequestParam(value = Constant.PAGE, required = false, defaultValue = "1") String page,
                                  @RequestParam(value = Constant.LIMIT, required = false, defaultValue = "10") String limit,
                                  Model model) {

        Map<String, Object> params = new HashMap<>();
        params.put(Constant.PAGE, page);
        params.put(Constant.LIMIT, limit);
        R r = orderFeignService.listWithItem(params);
        model.addAttribute("r", r);
        log.info("current user order data is {}", JSON.toJSONString(r));
        return "memberOrderList";
    }

    @RequestMapping("/ok")
    @ResponseBody
    public String ok() {

        return "ok";
    }
}
